#pragma once
#include <bits/stdint-uintn.h>

#include <vector>
namespace net_tools::base{

template<typename T>
class Hash{
 public:
  // N 散列函数 %N null 无数据时的指示
  Hash(uint64_t N,T null)
    :N_(N),
     null_(null),
     key_(N + 1,0),
     value_(N + 1,null_)
  {
  };
  ~Hash() = default;
  T& operator[](uint64_t index){
    uint64_t idx = index % N_;
    uint64_t cnt = 1;
    while( key_[idx] != index && value_[idx] != null_){
      idx = (idx + cnt*cnt ) % N_;
      ++cnt;
    }
    key_[idx] = index;
    return value_[idx];
  };
 private:
  uint64_t              N_;
  T                     null_;
  std::vector<uint64_t> key_;
  std::vector<T>        value_;
};

} // namespace net_tools::base